package com.ht.demo.admin.controller.system;

import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.appexception.ResultData;
import com.ht.demo.common.enums.OperateTypeEnum;
import com.ht.demo.common.pojo.bo.system.SysMenuBO;
import com.ht.demo.service.annotation.LoggerInfo;
import com.ht.demo.service.annotation.Permission;
import com.ht.demo.service.manager.system.SysMenuManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author hdengxian
 * @Date 2023/5/25 15:40
 */
@RestController
@RequestMapping("${basePath}")
public class SysMenuController {
    @Resource
    private SysMenuManager sysMenuManager;

    @Permission(permissionId = "system:menu:add", desc = "新增菜单")
    @LoggerInfo(title = "菜单管理", operateType = OperateTypeEnum.INSERT)
    @PostMapping("/system/menu/insert")
    public ResultData insertMenu(@RequestBody SysMenuBO menuBO) throws AppException {
        return new ResultData(sysMenuManager.insertMenu(menuBO));
    }

    @Permission(permissionId = "system:menu:edit", desc = "修改菜单")
    @LoggerInfo(title = "菜单管理", operateType = OperateTypeEnum.UPDATE)
    @PutMapping("/system/menu/update")
    public ResultData UpdateMenu(@RequestBody SysMenuBO menuBO) throws AppException {
        return new ResultData(sysMenuManager.UpdateMenu(menuBO));
    }

    @Permission(permissionId = "system:menu:remove", desc = "删除菜单")
    @LoggerInfo(title = "菜单管理", operateType = OperateTypeEnum.DELETE)
    @DeleteMapping("/system/menu/delete/{sysMenuId}")
    public ResultData delMenu(@PathVariable Long sysMenuId) throws AppException {
        return new ResultData(sysMenuManager.delMenu(sysMenuId));
    }

}
